
<script language="Javascript">

function vote()
{
	// Check if the options are OK.
	var	radio_vote_id = document.forms['poll_form'].elements['vote_id[]'];	
	var vote_id = 0;
	
	for (i = 0; i < radio_vote_id.length; ++i)
	{
		if (radio_vote_id.item(i).checked == true)
			vote_id = 1+i;
	}
	
	if (vote_id == 0)
		return false;
	
//	alert(vote_id);	
	
	<!-- IF IN_FB_IFRAME -->
	xmlhttpPost('../query.php', vote_id);
	<!-- ELSE -->
	xmlhttpPost('query.php', vote_id);
	<!-- ENDIF -->	
	
	return false;
}


function xmlhttpPost(strURL, vote_id) 
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) 
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() 
	{
        if (self.xmlHttpReq.readyState == 4)
		{
			updatepage();
        }
    }
    self.xmlHttpReq.send(getquerystring(vote_id));
}

function getquerystring(vote_id) 
{
    var	vote_key 	= document.forms['poll_form'].vote_key.value;
    var	user_id 	= document.forms['poll_form'].user_id.value;
    var	topic_id 	= document.forms['poll_form'].topic_id.value;
	
    qstr = 'mode=vote_a_poll&vote_key=' + vote_key + '&user_id=' + user_id + '&topic_id=' + topic_id + '&vote_id=' + vote_id;  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(){
    document.getElementById("vote_done").innerHTML = "<p>{L_VOTE_SUBMITTED}</p>";
    
    HideContent("submit_button");
    
}

function HideContent(d) 
{
	document.getElementById(d).style.display = "none";
}
</script>


	<form method="post" action="" name="poll_form" onsubmit="return vote();">

	<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>

		<div class="content">
			<h2>{POLL_QUESTION}</h2>
			<p class="author">{L_POLL_LENGTH}<!-- IF S_CAN_VOTE and L_POLL_LENGTH --><br /><!-- ENDIF --><!-- IF S_CAN_VOTE -->{L_MAX_VOTES}<!-- ENDIF --></p>

			<fieldset class="polls">
			<!-- BEGIN poll_option -->
				<dl class="<!-- IF poll_option.POLL_OPTION_VOTED -->voted<!-- ENDIF -->"<!-- IF poll_option.POLL_OPTION_VOTED --> title="{L_POLL_VOTED_OPTION}"<!-- ENDIF -->>
					<dt>
						<!-- IF S_CAN_VOTE -->
						<label for="vote_{poll_option.POLL_OPTION_ID}">{poll_option.POLL_OPTION_CAPTION}</label>
						<!-- ELSE -->{poll_option.POLL_OPTION_CAPTION}
						<!-- ENDIF -->
					</dt>
					<!-- IF S_CAN_VOTE -->
					<dd style="width: auto;">
						<!-- IF S_IS_MULTI_CHOICE -->
						<input type="checkbox" name="vote_id[]" id="vote_{poll_option.POLL_OPTION_ID}" value="{poll_option.POLL_OPTION_ID}"<!-- IF poll_option.POLL_OPTION_VOTED --> checked="checked"<!-- ENDIF --> />
						<!-- ELSE -->
						<input type="radio" name="vote_id[]" id="vote_{poll_option.POLL_OPTION_ID}" value="{poll_option.POLL_OPTION_ID}"<!-- IF poll_option.POLL_OPTION_VOTED --> checked="checked"<!-- ENDIF --> />
						<!-- ENDIF -->
					</dd>
					<!-- ENDIF -->
					
					<!-- IF S_DISPLAY_RESULTS -->
					<dd class="resultbar">
						<div class="<!-- IF poll_option.POLL_OPTION_PCT < 20 -->pollbar1<!-- ELSEIF poll_option.POLL_OPTION_PCT < 40 -->pollbar2<!-- ELSEIF poll_option.POLL_OPTION_PCT < 60 -->pollbar3<!-- ELSEIF poll_option.POLL_OPTION_PCT < 80 -->pollbar4<!-- ELSE -->pollbar5<!-- ENDIF -->" style="width:{poll_option.POLL_OPTION_PERCENT};">
							{poll_option.POLL_OPTION_RESULT}
						</div>
					</dd>
					<dd>
						<!-- IF poll_option.POLL_OPTION_RESULT == 0 -->{L_NO_VOTES}<!-- ELSE -->{poll_option.POLL_OPTION_PERCENT}<!-- ENDIF -->
					</dd>
					<!-- ENDIF -->
				</dl>
			<!-- END poll_option -->

			<!-- IF S_DISPLAY_RESULTS -->
				<dl>
					<dt>&nbsp;</dt>
					<dd class="resultbar">{L_TOTAL_VOTES} : {TOTAL_VOTES}</dd>
				</dl>
			<!-- ENDIF -->

			<!-- IF S_CAN_VOTE -->
				<dl style="border-top: none;">
					<dt>&nbsp;</dt>
					<dd class="resultbar"> 					
						<span id="submit_button" style="display:block;">
							<input type="submit" name="update" value="{L_SUBMIT_VOTE}" class="button1" />
						</span>
						
					</dd>
					<input type="hidden" name="vote_key" value="{S_VOTE_KEY}">
					<input type="hidden" name="user_id" value={S_USER_ID}>
					<input type="hidden" name="topic_id" value={S_VOTE_TOPIC_ID}>
				</dl>
			<!-- ENDIF -->

			<!-- IF not S_DISPLAY_RESULTS -->
				<dl style="border-top: none;">
					<dt>&nbsp;</dt>
					<dd class="resultbar"><a href="{U_VIEW_RESULTS}">{L_VIEW_RESULTS}</a></dd>
				</dl>
			<!-- ENDIF -->
			</fieldset>
		</div>

		<div id="vote_done"></div>
		<span class="corners-bottom"><span></span></span>
	</div>
		{S_FORM_TOKEN}
		{S_HIDDEN_FIELDS}
	</div>


	</form>
	
	
	
	<hr />
